package cn.itcast.mq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/msg")
public class MsgController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send/{exchange}")
    public ResponseEntity send(@PathVariable("exchange") String exchange) {
        String routingKey = "simple";
        Object message = "hello rabbit!";
        rabbitTemplate.convertAndSend(exchange, routingKey, message);
        return ResponseEntity.ok("发送成功" + new Date());
    }
}
